import { createErrorHandler } from './error-handler';
import { PacketSplitterOptions } from './packet-splitter';

export interface Device extends Record<string, any> {
  /** 蓝牙设备名称，某些设备可能没有 */
  name: string;
  deviceId: string;
  RSSI: number;
  advertisData: any;
  advertisServiceUUIDs: any;
  localName: string;
}

export enum ConnectionState {
  DISCONNECTED = 0,
  CONNECTING = 1,
  CONNECTED = 2
}
export enum EmitEvent {
  connectionStateChange,
  data,
  adapterStateChange,
  deviceFound,
  fullData
}
export type EventDataMap = {
  [EmitEvent.connectionStateChange]: { deviceId: string; connected: boolean };
  [EmitEvent.data]: { deviceId: string; serviceId: string; characteristicId: string; value: ArrayBuffer };
  [EmitEvent.adapterStateChange]: { available: boolean; discovering: boolean };
  [EmitEvent.deviceFound]: Device;
  [EmitEvent.fullData]: ArrayBuffer;
};
export type EventData<K extends EmitEvent> = K extends keyof EventDataMap ? EventDataMap[K] : never;

export interface BluetoothOptions {
  deviceNameFilter?: RegExp;
  rssiThreshold?: number;
  mtuSize?: number;
  createErrorHandler?: typeof createErrorHandler;
  splitterOptions?: PacketSplitterOptions;
}
